// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class Toast extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;


    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.anim();
    }

    start () {

    }

    init(string){
        this.label.string = string + "";
        this.node.y = (cc.winSize.height + this.node.height)/2;
        this.node.zIndex = 10000
    }

    anim(){
        this.node.runAction(
            cc.sequence(
                cc.moveTo(0.3, cc.v2(0, (cc.winSize.height -this.node.height)/2)),
                cc.delayTime(1.7),
                cc.moveTo(0.3, cc.v2(0, (cc.winSize.height + this.node.height)/2)),
                cc.callFunc(()=>{
                    this.node.destroy();
                })
            )
        );
    }

    // update (dt) {}
}
